/**
 * 
 */
package org.codesmell.util.rendermap.local;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * @author Uwe Schäfer, (schaefer@thomas-daily.de)
 */
public class ExceptionHelper
{

    public static RuntimeException wrap(final Throwable e)
    {
        return (RuntimeException) ((e instanceof RuntimeException) ? e : new WrappedException(e));
    }
    static class WrappedException extends RuntimeException
    {
        private Throwable e;

        @Override
        public boolean equals(final Object obj)
        {
            return e.equals(obj);
        }

        @Override
        public Throwable fillInStackTrace()
        {
            return e.fillInStackTrace();
        }

        @Override
        public Throwable getCause()
        {
            return e.getCause();
        }

        @Override
        public String getLocalizedMessage()
        {
            return e.getLocalizedMessage();
        }

        @Override
        public String getMessage()
        {
            return e.getMessage();
        }

        @Override
        public StackTraceElement[] getStackTrace()
        {
            return e.getStackTrace();
        }

        @Override
        public int hashCode()
        {
            return e.hashCode();
        }

        @Override
        public Throwable initCause(final Throwable cause)
        {
            return e.initCause(cause);
        }

        @Override
        public void printStackTrace()
        {
            e.printStackTrace();
        }

        @Override
        public void printStackTrace(final PrintStream s)
        {
            e.printStackTrace(s);
        }

        @Override
        public void printStackTrace(final PrintWriter s)
        {
            e.printStackTrace(s);
        }

        @Override
        public void setStackTrace(final StackTraceElement[] stackTrace)
        {
            e.setStackTrace(stackTrace);
        }

        @Override
        public String toString()
        {
            return e.toString();
        }

        public WrappedException(final Throwable e)
        {
            super(e);
            this.e = e;
        }

    }
}
